#ifndef _M_UTIL_H__
#define _M_UTIL_H__

#include<iostream>
#include <sys/types.h>
       #include <sys/stat.h>
       #include <unistd.h>
       #include <sys/types.h>
/*1. 获取系统时间
2. 获取文件大小
3. 创建目录
4. 获取文件所在目录*/
namespace mylog{

namespace util{

class date{
	public:
	static size_t now(){
		return (size_t)time(nullptr);
	}
};

class file{
	public:
	static bool exists(const std::string& name)
	{ struct stat st;
		return (stat(name.c_str(),&st)==0);

	}

	static std::string path(const std::string& name)
{
 if(name.empty()) return ".";
 int pos=name.find_last_of("/\\");
 if(pos==std::string::npos) return ".";
return name.substr(0,pos+1);


}

static void create_directory(const std::string& path)
{ // ./b/c
 if(path.empty()) return ;
 int pos=0,idx=0;
 while(idx<path.size())
 {
pos=path.find_first_of("/\\",idx);
if(pos==std::string::npos) mkdir(path.c_str(),0777);
std::string parent_dir=path.substr(0,pos+1);
if(exists(parent_dir)) {idx=pos+1;continue;}
mkdir(parent_dir.c_str(),0777);
idx=pos+1;
 }

}






};








}










}

#endif